__author__ = 'carlxie'
from layer.Layer import Layer
from layer.util import *
from layer.LayerType import LayerType

class LeruLayer(Layer):
    def __init__(self,preLayer):
        (w,h,d) = preLayer.output.shape
        super(LeruLayer,self).__init__(preLayer,LayerType.TANH_TYPE,w,h,d)

    def forward_prop(self):
        self.output = vec_leru(self.preLayer.output)

    def back_prop(self):
        if self.preLayer.score.shape == self.delta.shape:
            self.preLayer.delta = self.delta * vec_der_tanh(self.preLayer.score)
        else:
            preLayerScore = self.preLayer.score.reshape(self.delta.shape)
            delta = self.delta * preLayerScore
            self.preLayer.delta = delta.reshape(self.preLayer.output.shape)

